Now that we've learned about NumPy let's test your knowledge. We'll start off with a few simple tasks and then you'll be asked some more complicated questions.
IMPORTANT NOTE! Make sure you don't run the cells directly above the example output shown, otherwise you will end up writing over the example output!
In [1]:
import numpy as np
In [ ]:
# CODE HERE
In [2]:
np.zeros(10)
Out[2]:
In [ ]:
# CODE HERE
In [3]:
np.ones(10)
Out[3]:
In [ ]:
# CODE HERE
In [4]:
np.ones(10) * 5
Out[4]:
In [ ]:
# CODE HERE
In [5]:
np.arange(10,51)
Out[5]:
In [ ]:
# CODE HERE
In [6]:
np.arange(10,51,2)
Out[6]:
In [ ]:
# CODE HERE
In [7]:
np.arange(9).reshape(3,3)
Out[7]:
In [ ]:
# CODE HERE
In [8]:
np.eye(3)
Out[8]:
In [ ]:
# CODE HERE
In [15]:
np.random.rand(1)
Out[15]:
In [ ]:
# CODE HERE
In [33]:
np.random.randn(25)
Out[33]:
In [ ]:
In [35]:
np.arange(1,101).reshape(10,10) / 100
Out[35]:
In [ ]:
In [36]:
np.linspace(0,1,20)
Out[36]:
In [ ]:
# CODE HERE
In [38]:
mat = np.arange(1,26).reshape(5,5)
mat
Out[38]:
In [39]:
# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW
# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T
# BE ABLE TO SEE THE OUTPUT ANY MORE
In [40]:
mat[2:,1:]
Out[40]:
In [29]:
# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW
# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T
# BE ABLE TO SEE THE OUTPUT ANY MORE
In [41]:
mat[3,4]
Out[41]:
In [30]:
# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW
# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T
# BE ABLE TO SEE THE OUTPUT ANY MORE
In [42]:
mat[:3,1:2]
Out[42]:
In [31]:
# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW
# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T
# BE ABLE TO SEE THE OUTPUT ANY MORE
In [46]:
mat[4,:]
Out[46]:
In [32]:
# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW
# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T
# BE ABLE TO SEE THE OUTPUT ANY MORE
In [49]:
mat[3:5,:]
Out[49]:
In [ ]:
# CODE HERE
In [50]:
mat.sum()
Out[50]:
In [ ]:
# CODE HERE
In [51]:
mat.std()
Out[51]:
In [ ]:
# CODE HERE
In [53]:
mat.sum(axis=0)
Out[53]:
We worked a lot with random data with numpy, but is there a way we can insure that we always get the same random numbers? Click Here for a Hint
In [ ]:
np.random.seed(101)